home *** CD-ROM | disk | FTP | other *** search
-
- #include "lharc.h"
-
- int matchpattern(register uchar *s,register uchar *p)
- {
- register uchar s_c,p_c;
- register int matched,reverse;
-
- for (;(p_c=*p++)!='\0';)
- {
- s_c=*s++;
-
- switch (p_c)
- {
- case '@':
- if (s_c!=*p++)
- return(FAULT);
- break;
- case '?':
- if (s_c=='\0')
- return(FAULT);
- break;
- case '*':
- if (s_c=='\0')
- return((*p=='\0') ? SUCCS :FAULT);
- else
- {
- if (*p!='\0')
- {
- s--;
- while (!matchpattern(s,p))
- if (*++s=='\0')
- return(FAULT);
- }
- return(SUCCS);
- }
- case '[':
- matched=FAULT;
-
- if (*p=='^')
- {
- reverse=SUCCS;
- p++;
- }
- else
- reverse=FAULT;
-
- for (; (p_c=*p++)!='\0' && p_c!=']';)
- {
- if (p_c=='-')
- {
- if (s_c<=*p++ && s_c>=p[-3])
- matched=SUCCS;
- }
- else if (p_c=='@' && s_c==*p++)
- matched=SUCCS;
- else if (s_c==p_c && p_c!='|')
- matched=SUCCS;
- }
-
- if (matched==reverse)
- return(FAULT);
-
- break;
- default:
- if (s_c!=p_c)
- return(FAULT);
- break;
- }
- }
-
- return(*s=='\0');
- }
-
- int chk_wild(uchar *fname,uchar *fspec,int Wild)
- {
- if (*fspec)
- {
- register uchar *p=fspec;
-
- if (*p++=='*' && (*p=='\0' || (*p++=='.' && *p++=='*' && *p++=='\0')))
- return(SUCCS);
- else
- {
- register int res=0,len=(int) strlen(fspec);
-
- p=strtok(fspec,", ");
- while (p)
- {
- if (Wild)
- res=(!strcmp(fname,p));
- else
- res=matchpattern(fname,p);
-
- if (res)
- {
- while (*p++);
- if ((long) ((--p)-fspec)<len)
- *p=',';
- return(SUCCS);
- }
- else if ((p=strtok(NULL,", "))!=NULL)
- p[-1]=',';
- }
- }
- }
-
- return(FAULT);
- }
-